from haystack import indexes
from course import models

class CouseIndex(indexes.SearchIndex,indexes.Indexable):
    #全文所搜的字段
    #document是全文搜索
    text=indexes.CharField(document=True,use_template=False)
    #索引字段model_attr 关联模型字段那个属性
    coursename=indexes.CharField(model_attr='coursename')
    desc=indexes.CharField(model_attr='coursedesc')
    price=indexes.DecimalField(model_attr='price')
    id=indexes.CharField(model_attr='id')
    cover=indexes.CharField(model_attr='cover')
    content=indexes.CharField(model_attr='content')
    def get_model(self):
        return models.Course

    def index_queryset(self, using=None):
        return self.get_model().objects.filter(flag=True)
    #设置text字段关联的字段
    def prepare_text(self, obj):
        return u"%s %s %s "%(obj.coursename,obj.coursedesc,obj.content)
